<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>领料审批待办</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<table class="layui-hide" id="test" lay-filter="test"></table>
<table class="layui-hide" id="testDetial" lay-filter="testDetial"></table>

<div id="formDiv3" hidden>
	<form class="layui-form" id="delForm">
		<input id="pickID" name="pickID" type="hidden"><br>
		<label class="layui-form-label">备注</label>
		<div class="layui-textarea-inline">
			<textarea lay-verify="remark" class="layui-textarea" id="remark" name="remark" style="width: 65%;"></textarea>
		</div><br>
		<button class="layui-btn layui-btn-blue" id="approval1" lay-submit lay-filter="approval1" style="margin-left:20%">通过</button>
		&emsp;&emsp;&emsp;&emsp;<button class="layui-btn layui-btn-blue" id="approval2" lay-submit lay-filter="approval2">驳回</button>
		&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</form>
</div>
 
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="add"><i class="layui-icon layui-icon-add-1">  审批</i></button>
	</div>
</script>
              
          
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
<jsp:include page="ScriptInc.jsp"></jsp:include>
<script>
layui.use(['table','layer','upload','form'], function(){
	var table = layui.table;
	var layer = layui.layer,
    form = layui.form;
	
	var $ = layui.jquery, active = {
			reload:function () {
				var keyword = $("#keyword").val();
				console.log(keyword)
				table.reload('contenttable',{
					method:'get',
					where:{panum: keyword}
				});
			}
		}
	$('.layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
	table.render({
	    elem: '#test'
	    ,url:'${pageContext.request.contextPath }/approvalRecord/listPageApprovalRecord.do'
	    ,toolbar: '#toolbarDemo'
	    ,title: '领料审批待办数据表'
	    ,id :'contenttable'
	    ,limits:[10,20,30]
	    ,cols: [[
	      {type: 'checkbox', fixed: 'left'}
	      ,{type: 'numbers', title:'序号', fixed: 'left', width:'5%', unresize: true, sort: true}
	      ,{field:'approvalType', title:'审批类型'}
	      ,{field:'submitDate', title:'提交日期',templet: function(d){
		          return timestampToDateTime(d.submitDate.time);
  	      }}
	      ,{field:'submitterName', title:'提交人'}
	      ,{field:'approverName', title:'审批人'}
	    ]]
	    ,page: true
	});
	
	//监听行单击事件
	table.on('row(test)', function(obj){
	  table.render({
		    elem: '#testDetial'
		    ,url:'${pageContext.request.contextPath }/pickApply/findPickApplyByID.do'
		    ,where:{pickID: obj.data.pickID}
		    ,title: '领料申请单数据表'
		    ,id :'contentDetialTable'
		    ,limits:[10,20,30]
		    ,cols: [[
		      {type: 'numbers', fixed: 'left', title:'序号'}
		      ,{field:'pickNum', title:'单据号'}
		      ,{field:'pickDate', title:'日期', templet: function(d){
		          return timestampToDate(d.pickDate.time);
		      }}
		      ,{field:'pickDeptName', title:'部门'}
		      ,{field:'demandDate', title:'需求日期', templet: function(d){
		          return timestampToDate(d.demandDate.time);
		      }}
		      ,{field:'generateOrderID', title:'生产订单号ID', templet: function(d){
		    	  if (d.generateOrderID == '0') {
		    		  return '';
				} else {
					return d.generateOrderID;
				}
		      }}
		      ,{field:'pickPersonName', title:'制单人'}
		      ,{field:'approvalRecord', title:'领料明细', templet: function(d){
		    	  return "<a href='javascript:void(0)' style='color:#4D61B3' onclick='attachDeviceEvent(\""+d.pickID+"\")'>"+'查看明细'+"</a>";
		      }}
		    ]]
		    ,page: false
		});
	});
	
	//头工具栏事件
	table.on('toolbar(test)', function(obj){
		var checkStatus = table.checkStatus(obj.config.id);
		var data = checkStatus.data;
		if (data.length <= 0) {
			toastr.warning("请选择一条记录！");
    		return false;
		}
		if (data.length > 1) {
			toastr.warning("只能选择一条记录！");
    		return false;
		}
	    switch(obj.event){
	    	case 'add':
	    		layer.open({
					  type: 1 		//Page层类型
					  ,area: ['500px', '300px'] //宽  高
					  ,title: '审批'
					  ,shade: 0.6 	//遮罩透明度
					  ,shadeClose: true //点击遮罩关闭
					  ,maxmin: true //允许全屏最小化
					  ,anim: 1 		//0-6的动画形式，-1不开启
					  ,content: $('#formDiv3')
					  ,success: function () {
						  document.getElementById("delForm").reset();
						  $('#pickID').val(data[0].pickID);
					  }
					  ,end: function () {
						  var formDiv = document.getElementById('formDiv3');
						  formDiv.style.display = '';
					  }
					});
	      	break;
	    };
	});
	
	/**
     * 通用表单提交(AJAX方式)审批
     */
	form.on('submit(approval1)', function (data) {
		$("#approval1").attr("disabled",true);
		$.ajax({
			url : '${pageContext.request.contextPath }/pickApply/approvalPickApply2.do?reserve1=3',
			type : "post",
			data : $('#delForm').serialize(),
		}).done(
			function(res) {
				if (res > 0) {
					toastr.success('审批成功');
					setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
						//关闭模态框
						// 父页面刷新
						window.location.reload();  
					},2000);
				}
			}
		).fail(
			function(res) {
				toastr.error('审批失败');
			}
		)
		return false;
	});
	form.on('submit(approval2)', function (data) {
		$("#approval2").attr("disabled",true);
		$.ajax({
			url : '${pageContext.request.contextPath }/pickApply/approvalPickApply2.do?reserve1=4',
			type : "post",
			data : $('#delForm').serialize(),
		}).done(
			function(res) {
				if (res > 0) {
					toastr.success('驳回成功');
					setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
						//关闭模态框
						// 父页面刷新
						window.location.reload();  
					},2000);
				}
			}
		).fail(
			function(res) {
				toastr.error('驳回失败');
			}
		)
		return false;
	});
});
toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
//审批记录
function attachDeviceEvent(pickID){
    layer.open({
        type: 1 					//Page层类型
        ,area: ['80%', '80%']   //宽  高
        ,title: '领料明细'
        ,shade: 0.6 				//遮罩透明度
        ,maxmin: true 			    //允许全屏最小化
        ,anim: 1 					//0-6的动画形式，-1不开启
        ,content: '<table class="layui-hide" id="lookupTable1" lay-filter="lookupTable1"></table>'
        ,success: function(){
            layui.use(['table'], function(){
                var table = layui.table;
                table.render({
                    elem: '#lookupTable1'
                    ,url: '${pageContext.request.contextPath }/pickApply/listPagePickApplyDetail.do'
                    ,title: '领料明细'
                    ,id :'contenttable'
                    ,where:{pickID: pickID}
	                ,limits:[10,20,30]
	    		    ,cols: [[
	    		      {type: 'numbers', fixed: 'left', title:'序号'}
	    		      ,{field:'stockNum', title:'配件编号'}
	    		      ,{field:'stockName', title:'配件名称'}
	    		      ,{field:'stockModel', title:'规格型号'}
	    		      ,{field:'reserve1', title:'计量单位'}
	    		      ,{field:'reserve2', title:'包装规格'}
	    		      ,{field:'reserve3', title:'批次号'}
	    		      ,{field:'quantity', title:'数量'}
	    		    ]]
	    		    ,page: true
                });
            });
        }
    });
}
</script>

</body>
</html>